AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_spawnmenu.lua" )
AddCSLuaFile( "player_extension.lua" )

include( 'shared.lua' )
include( 'player.lua' )

function GM:PlayerSpawn( pl )
	pl:UnSpectate()
	
	hook.Call( "PlayerLoadout", GAMEMODE, pl )
	hook.Call( "PlayerSetModel", GAMEMODE, pl )
	
	GAMEMODE:SetPlayerSpeed( pl, 175, 300 )
end

function GM:PlayerLoadout( pl )
	pl:RemoveAllAmmo()
	
	--[[pl:GiveAmmo( 256,	"Pistol", 		true )
	pl:GiveAmmo( 256,	"SMG1", 		true )
	pl:GiveAmmo( 5,		"grenade", 		true )
	pl:GiveAmmo( 64,	"Buckshot", 	true )
	pl:GiveAmmo( 32,	"357", 			true )
	pl:GiveAmmo( 32,	"XBowBolt", 	true )
	pl:GiveAmmo( 6,		"AR2AltFire", 	true )]]
	
	-- pl:GiveAmmo(30, "Pistol", true)
	pl:Give("p99_weapon")
	
	pl:Give("weapon_physcannon")
	pl:Give("gmod_tool")
	pl:Give("gmod_camera")
	pl:Give("weapon_physgun")
	
	local cl_defaultweapon = pl:GetInfo("cl_defaultweapon")
	
	if (pl:HasWeapon(cl_defaultweapon)) then
		pl:SelectWeapon(cl_defaultweapon)
	end
	
	
end

function GM:OnPhysgunFreeze( weapon, phys, ent, ply )
	
	self.BaseClass:OnPhysgunFreeze( weapon, phys, ent, ply )
	
	ply:SendHint( "PhysgunUnfreeze", 0.3 )
	ply:SuppressHint( "PhysgunFreeze" )
	
end

function GM:OnPhysgunReload( weapon, ply )
	local num = ply:PhysgunUnfreeze()
	
	if ( num > 0 ) then
		ply:SendLua( "GAMEMODE:UnfrozeObjects("..num..")" )
	end
	
	ply:SuppressHint( "PhysgunReload" )
end

function GM:PlayerShouldTakeDamage( ply, attacker )
	-- Should always take damage in "With Friends Like These". -- Ricky26
	return true
end


function GM:ShowHelp( ply )
	ply:ConCommand( "SchoolMe" )
end


function GM:PlayerInitialSpawn( ply )
	ply.Cash = 0.00
	ply.Radiation = 0.0

	local meta = FindMetaTable("Player")
	if meta and meta.hooked == nil then
		meta.oFireBullets, meta.FireBullets = ply.FireBullets, meta.nFireBullets
		
		-- Add other hooked function originals here. -- Ricky26
		
		meta.hooked = 1
	end
	
	self.BaseClass:PlayerInitialSpawn(ply)
	
	PlayerDataUpdate(ply)
end


function GM:CreateEntityRagdoll( entity, ragdoll )

	-- Replace the entity with the ragdoll in cleanups etc
	undo.ReplaceEntity( entity, ragdoll )
	cleanup.ReplaceEntity( entity, ragdoll )
	
end


function GM:PlayerUnfrozeObject( ply, entity, physobject )

	local effectdata = EffectData()
		effectdata:SetOrigin( physobject:GetPos() )
	util.Effect( "phys_unfreeze", effectdata, true, true )	
	
end


function GM:PlayerFrozeObject( ply, entity, physobject )

	local effectdata = EffectData()
		effectdata:SetOrigin( physobject:GetPos() )
	util.Effect( "phys_freeze", effectdata, true, true )	
	
end
